/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAL;
import DTO.DTObenhnhan;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Lee No Son
 */
public class DALbenhnhan {
    ConnectionBD conn;
    public DALbenhnhan(){
        conn = new ConnectionBD();
    }
    
    public ArrayList<DTObenhnhan> layTatCaBenhNhan(){
        conn.getConnectionBD();
        try {
            
            ArrayList<DTObenhnhan> listBenhNhan = new ArrayList<>();//khoi tao danh sach benh nhan
            String queryString = "SELECT * FROM `benhnhan`";
            PreparedStatement stmt = conn.getCnt().prepareStatement(queryString);
            ResultSet rs = stmt.executeQuery();
            while(rs.next()){
                listBenhNhan.add(new DTObenhnhan(rs));
            }
            return listBenhNhan;
        } catch (Exception e) {
            System.err.print(e.getMessage());
            return null;
            
        }
        finally{
            conn.closeCnt();
        }
    }
}
